<?php 
session_start(); // on relaye la session 
if(isset($_SESSION["is_registered"]) && $_SESSION["is_registered"] == "registered"){
		$enregistrer = $_SESSION["is_registered"];
}else{
	header("location:../../../menu.php"); // redirection en cas d'echec
}
require_once('../../../Connections/microassur.php'); 
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_rs = "-1";
if (isset($_GET['Identifiant_region'])) {
  $colname_rs = $_GET['Identifiant_region'];
}
mysql_select_db($database_microassur, $microassur);
$query_rs = sprintf("SELECT * FROM unite WHERE Etat_unite='A' and Identifiant_region = %s", GetSQLValueString($colname_rs, "int"));
$rs = mysql_query($query_rs, $microassur) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
if($totalRows_rs==0){

if ((isset($_GET['Identifiant_region'])) && ($_GET['Identifiant_region'] != "")) {
  $deleteSQL = sprintf("DELETE FROM region WHERE Identifiant_region=%s",
                       GetSQLValueString($_GET['Identifiant_region'], "int"));

  mysql_select_db($database_microassur, $microassur);
  mysql_query("START TRANSACTION");
  $Result1 = mysql_query($deleteSQL, $microassur) or die(mysql_error());
if($Result1) {mysql_query("commit");header("Location: modregion.php?supp=success");}

else {mysql_query("rollback"); header("Location: modregion.php?supp=err&Identifiant_region=".$colname_rs);}

}
}
else
{	mysql_query("rollback");
  header("Location: modregion.php?supp=existunite&Identifiant_region=".$colname_rs);

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
</head>

<body>
</body>
</html><?php ob_end_flush();?>
